import React, { forwardRef, useState, useImperativeHandle, ChangeEvent, useRef, useEffect } from 'react';
import { Button, Modal, Input, Table, Space, Form, Pagination, Select, Radio, Image, Upload, DatePicker, UploadProps, DatePickerProps, TreeSelect, Switch } from 'antd';
import { WomanOutlined, ManOutlined, PlusOutlined, InboxOutlined, PaperClipOutlined } from '@ant-design/icons';
import SmartMap from '../../../components/smart-map';
import systemApi from '../../../api/system';
import * as XLSX from "xlsx";
import { addItemToUniquenList, commonErrorMsg, downloadAndRenameFile, isEmpty, readWorkBookData, toastShort } from '../../../utils';
import LoadingWapper from '../../../components/loading/LoadingWapper';
import { BJHSpeciesInfoType, SelectOption, SpeciesInfoType } from '../../../utils/types';
import statisticalAnalysisTools from './../../../statistical-analysis-temp/src';
import { TypeWorkBookReadResult } from '../../../types';
import { processWordParagraphBlockList } from '../../../statistical-analysis-temp/src/utils';

interface Props {
    showTitle?: boolean
    onFinish?: Function
};

const { TextArea } = Input;
const { RangePicker } = DatePicker;
const { Dragger } = Upload;

interface AnalysFrom {
    currentFileName: string
    currentYear?: string
}

const SpeciesNameFileModal = (props: Props, ref: any) => {
    useImperativeHandle(ref, () => ({
        openModal: openModal
    }));

    const {
        onFinish
    } = props;

    const [form] = Form.useForm<AnalysFrom>();

    const [formData, setFormData] = useState<AnalysFrom>({
        currentFileName: null,
        currentYear: '2023'
    });

    const smartMapRef = useRef(null);
    const delayTimer = useRef(null);
    const [isModalOpen, setIsModalOpen] = useState(false);
    const [submitLoading, setSubmitLoading] = useState(false);
    const [currentFileName, setCurrentFileName] = useState("");
    const [analysType, setAnalysType] = useState('');
    const [loading, setLoading] = useState(false);
    const [mergedRowDataList, setMergedRowDataList] = useState<BJHSpeciesInfoType[]>([]);
    const tempSheetData = useRef<TypeWorkBookReadResult[]>(null);
    const tempWorkSheet = useRef<string[][]>(null);
    const [yearOptions, setYearOptions] = useState<SelectOption[]>([]);
    const [currentYear, setCurrentYear] = useState('');

    useEffect(() => {
        let tempEndYearOptions: SelectOption[] = [];
        for (let i = 0; i < 50; i++) {
            const lastYear = new Date().getFullYear() - 1;
            tempEndYearOptions.push({
                label: `${lastYear + i}年`,
                value: `${lastYear + i}`,
            })
        }
        setYearOptions(tempEndYearOptions);
    }, []);

    const openModal = (analysType: string) => {
        console.log("analysType--->", analysType)
        setIsModalOpen(true);
        setAnalysType(analysType);
    };

    useEffect(() => {
        return () => {
            delayTimer.current && clearTimeout(delayTimer.current);
        }
    }, []);

    const handleConfirm = async () => {
        try {
            const values = await form.validateFields();
            setSubmitLoading(true);
            delayTimer.current = setTimeout(() => {
                setSubmitLoading(false);
            }, 1000);
            switch (analysType) {
                case 'SpeciesBook':
                    console.log("mergedRowDataList--->", mergedRowDataList)
                    const speciesBookResult = statisticalAnalysisTools.createSpeciesBook({
                        mergedRowDataList,
                        isProtection: false
                    })
                    // console.log("speciesBookResult---->", speciesBookResult);
                    // console.log("speciesBookResult---->", JSON.stringify({
                    //     paragraphList: speciesBookResult.reportParagraphList
                    // }))
                    // return;
                    let speciesBookParams = {
                        data: JSON.stringify({
                            paragraphList: speciesBookResult.reportParagraphList
                        })
                    }
                    systemApi.exportWordReport(speciesBookParams)
                        .then(res => {
                            downloadAndRenameFile(res.data.url, '物种名录');
                            if (speciesBookResult.matchFailureParagraphList.length) {
                                let speciesBookFailureParams = {
                                    data: JSON.stringify({
                                        paragraphList: speciesBookResult.matchFailureParagraphList
                                    })
                                }
                                systemApi.exportWordReport(speciesBookFailureParams)
                                    .then(res => {
                                        downloadAndRenameFile(res.data.url, '物种名录运行结果反馈')
                                    })
                                    .catch(err => {
                                        console.log("失败", err)
                                    })
                            }
                        })
                        .catch(err => {
                            console.log("失败", err)
                        })
                    break;
                case 'ProtectionSpeciesBook':
                    const statisticalAnalysisResult = statisticalAnalysisTools.createSpeciesBook({
                        mergedRowDataList,
                        isProtection: true
                    })
                    console.log("statisticalAnalysisResult--->", statisticalAnalysisResult)
                    console.log("statisticalAnalysisResult--->", JSON.stringify({
                        paragraphList: statisticalAnalysisResult.reportParagraphList
                    }))
                    let statisticalAnalysisParams = {
                        data: JSON.stringify({
                            paragraphList: statisticalAnalysisResult.reportParagraphList
                        })
                    }
                    systemApi.exportWordReport(statisticalAnalysisParams)
                        .then(res => {
                            downloadAndRenameFile(res.data.url, '保护物种名录');
                            setSubmitLoading(false);
                            if (statisticalAnalysisResult.matchFailureParagraphList.length) {
                                let statisticalAnalysisFailureParams = {
                                    data: JSON.stringify({
                                        paragraphList: statisticalAnalysisResult.matchFailureParagraphList
                                    })
                                }
                                // console.log("statisticalAnalysisFailureParams--->", statisticalAnalysisFailureParams)
                                systemApi.exportWordReport(statisticalAnalysisFailureParams)
                                    .then(res => {
                                        downloadAndRenameFile(res.data.url, '保护物种名录运行结果反馈')
                                    })
                                    .catch(err => {
                                        console.log("失败", err)
                                    })
                            }
                        })
                        .catch(err => {
                            console.log("失败", err)
                        })
                    break;
                case 'SpeciesStatistics':
                    const speciesStatisticsResult = statisticalAnalysisTools.createSpeciesStatisticsReport({
                        mergedRowDataList,
                    })
                    // console.log("speciesStatisticsResult--->", speciesStatisticsResult);
                    // console.log("speciesStatisticsResult--->", JSON.stringify({
                    //     paragraphList: speciesStatisticsResult.reportParagraphList
                    // }));
                    let speciesStatisticsParams = {
                        data: JSON.stringify({
                            paragraphList: speciesStatisticsResult.reportParagraphList
                        })
                    }
                    // return;
                    systemApi.exportWordReport(speciesStatisticsParams)
                        .then(res => {
                            downloadAndRenameFile(res.data.url, '物种统计');
                            setSubmitLoading(false);
                            if (speciesStatisticsResult.matchFailureParagraphList.length) {
                                let speciesStatisticsFailureParams = {
                                    data: JSON.stringify({
                                        paragraphList: speciesStatisticsResult.matchFailureParagraphList
                                    })
                                }
                                systemApi.exportWordReport(speciesStatisticsFailureParams)
                                    .then(res => {
                                        downloadAndRenameFile(res.data.url, '物种统计运行结果反馈')
                                    })
                                    .catch(err => {
                                        console.log("失败", err)
                                    })
                            }
                        })
                        .catch(err => {
                            console.log("失败", err)
                            setSubmitLoading(false);
                            toastShort("error", commonErrorMsg)
                        })
                    break;
                case 'FloraStatistics':
                    console.log("mergedRowDataList--->", mergedRowDataList)
                    setSubmitLoading(true);
                    let speciesUniquenNameList: string[] = [];
                    let genusUniquenNameList: string[] = [];
                    let familyUniquenNameList: string[] = [];
                    mergedRowDataList.forEach(row => {
                        speciesUniquenNameList = addItemToUniquenList(row.speciesName, speciesUniquenNameList);
                        genusUniquenNameList = addItemToUniquenList(row.genus, genusUniquenNameList);
                        familyUniquenNameList = addItemToUniquenList(row.family, familyUniquenNameList);
                    })
                    let floraQueryParams = {
                        familyList: familyUniquenNameList,
                        genusList: genusUniquenNameList,
                        speciesList: speciesUniquenNameList
                    }
                    systemApi.floraQuery(floraQueryParams)
                        .then(res => {
                            console.log("区系查询结果---->", res)
                            //@ts-ignore
                            const floraStatisticsResult = statisticalAnalysisTools.createFloraReport({ mergedRowDataList, floraQueryResult: res.data, type: 'analys' });
                            console.log("floraStatisticsResult--->", floraStatisticsResult)
                            let speciesStatisticsParams = {
                                data: JSON.stringify({
                                    paragraphList: floraStatisticsResult.reportParagraphList
                                })
                            }
                            systemApi.exportWordReport(speciesStatisticsParams)
                                .then(res => {
                                    downloadAndRenameFile(res.data.url, '区系分析');
                                    setSubmitLoading(false);
                                })
                                .catch(err => {
                                    console.log("失败", err)
                                    setSubmitLoading(false);
                                    toastShort("error", commonErrorMsg)
                                })
                        })
                        .catch(err => {
                            console.log("区系查询结果---->err", err)
                        })
                    break;
                case 'FloraAnalysisReport':
                    setSubmitLoading(true);
                    let speciesUniquenNameList1: string[] = [];
                    let genusUniquenNameList1: string[] = [];
                    let familyUniquenNameList1: string[] = [];
                    mergedRowDataList.forEach(row => {
                        speciesUniquenNameList1 = addItemToUniquenList(row.speciesName, speciesUniquenNameList1);
                        genusUniquenNameList1 = addItemToUniquenList(row.genus, genusUniquenNameList1);
                        familyUniquenNameList1 = addItemToUniquenList(row.family, familyUniquenNameList1);
                    })
                    let floraQueryParams1 = {
                        familyList: familyUniquenNameList1,
                        genusList: genusUniquenNameList1,
                        speciesList: speciesUniquenNameList1
                    }
                    systemApi.floraQuery(floraQueryParams1)
                        .then(res => {
                            // console.log("区系查询结果---->", res)
                            //@ts-ignore
                            const floraStatisticsResult = statisticalAnalysisTools.createFloraReport({ mergedRowDataList, floraQueryResult: res.data, type: 'report' });
                            // console.log("floraStatisticsResult--->", floraStatisticsResult)
                            let speciesStatisticsParams = {
                                data: JSON.stringify({
                                    paragraphList: floraStatisticsResult.reportParagraphList,
                                    speciesInfoList: mergedRowDataList,
                                })
                            }
                            // console.log("区系数据是---->", JSON.stringify({
                            //     paragraphList: floraStatisticsResult.reportParagraphList,
                            //     speciesInfoList: mergedRowDataList,
                            // }))
                            // return;
                            systemApi.exportWordReport(speciesStatisticsParams)
                                .then(res => {
                                    downloadAndRenameFile(res.data.url, '区系分析报告');
                                    setSubmitLoading(false);
                                })
                                .catch(err => {
                                    console.log("失败", err)
                                    setSubmitLoading(false);
                                    toastShort("error", commonErrorMsg)
                                })
                        })
                        .catch(err => {
                            console.log("区系查询结果---->err", err)
                        })
                    break;
                case 'EnvironmentalFactorAnalysis':
                    const environmentalFactorAnalysisResult = statisticalAnalysisTools.environmentalFactorAnalysis({
                        //@ts-ignore
                        airMonitoringSheetData: tempSheetData.current[0].sheetData,
                        //@ts-ignore
                        waterEnvironmentSheetData: tempSheetData.current[1].sheetData,
                        //@ts-ignore
                        soilMonitoringSheetData: tempSheetData.current[2].sheetData,
                        year: currentYear
                    })
                    let environmentalFactorAnalysisParams = {
                        data: JSON.stringify({
                            paragraphList: processWordParagraphBlockList(environmentalFactorAnalysisResult)
                        })
                    }
                    systemApi.exportWordReport(environmentalFactorAnalysisParams)
                        .then(res => {
                            downloadAndRenameFile(res.data.url, '环境因子监测分析报告');
                            setSubmitLoading(false);
                        })
                        .catch(err => {
                            console.log("失败", err)
                            setSubmitLoading(false);
                            toastShort("error", commonErrorMsg)
                        })
                    break;
                case 'VegetationAndEcosystem':
                    const vegetationAndEcosystemAnalysisResult = statisticalAnalysisTools.vegetationAndEcosystemAnalysis({
                        ecosystemTypeSheetData: tempSheetData.current[1].sheetData.filter(row => row['生态系统类型'] && row['面积（公顷）']),
                        vegetationTypeSheetData: tempSheetData.current[0].sheetData.filter(row => row['植被型'] && row['植被型组'] && row['植被群系和亚群系'] && row['面积（公顷）'])
                    })
                    let vegetationAndEcosystemAnalysisParams = {
                        data: JSON.stringify({
                            paragraphList: vegetationAndEcosystemAnalysisResult
                        })
                    }
                    systemApi.exportWordReport(vegetationAndEcosystemAnalysisParams)
                        .then(res => {
                            downloadAndRenameFile(res.data.url, '植被和生态系统类型统计分析报告');
                            setSubmitLoading(false);
                        })
                        .catch(err => {
                            console.log("失败", err)
                            setSubmitLoading(false);
                            toastShort("error", commonErrorMsg)
                        })
                    break;
                case 'LandUseTypeAnalysis':
                    const landUseTypeAnalysisResult = statisticalAnalysisTools.landUseTypeAnalysis({
                        workSheet: tempWorkSheet.current,
                    })
                    console.log("landUseTypeAnalysisResult--->", landUseTypeAnalysisResult)
                    let landUseTypeAnalysisParams = {
                        data: JSON.stringify({
                            paragraphList: landUseTypeAnalysisResult
                        })
                    }
                    systemApi.exportWordReport(landUseTypeAnalysisParams)
                        .then(res => {
                            downloadAndRenameFile(res.data.url, '地类统计分析');
                            setSubmitLoading(false);
                        })
                        .catch(err => {
                            console.log("失败", err)
                            setSubmitLoading(false);
                            toastShort("error", commonErrorMsg)
                        })
                    break;
                case 'SocialEconomicStatistics':
                    const socialEconomicStatisticsResult = statisticalAnalysisTools.socialEconomicStatistics({
                        workSheet: tempWorkSheet.current,
                    })
                    console.log("socialEconomicStatisticsResult--->", socialEconomicStatisticsResult)
                    let socialEconomicStatisticsParams = {
                        data: JSON.stringify({
                            paragraphList: socialEconomicStatisticsResult
                        })
                    }
                    systemApi.exportWordReport(socialEconomicStatisticsParams)
                        .then(res => {
                            downloadAndRenameFile(res.data.url, '社区经济统计');
                            setSubmitLoading(false);
                        })
                        .catch(err => {
                            console.log("失败", err)
                            setSubmitLoading(false);
                            toastShort("error", commonErrorMsg);
                        })
                    break;
                case 'ManagementOrganizationAndPersonnel':
                    const managementOrganizationAndPersonnelResult = statisticalAnalysisTools.managementOrganizationAndPersonnel({
                        workSheet: tempWorkSheet.current,
                    })
                    console.log("managementOrganizationAndPersonnelResult--->", managementOrganizationAndPersonnelResult)
                    let managementOrganizationAndPersonnelParams = {
                        data: JSON.stringify({
                            paragraphList: managementOrganizationAndPersonnelResult
                        })
                    }
                    systemApi.exportWordReport(managementOrganizationAndPersonnelParams)
                        .then(res => {
                            downloadAndRenameFile(res.data.url, '自然保护地管理评价');
                            setSubmitLoading(false);
                        })
                        .catch(err => {
                            console.log("失败", err)
                            setSubmitLoading(false);
                            toastShort("error", commonErrorMsg);
                        })
                    break;
                case 'ManagementEffectivenessEvaluation':
                    const managementEffectivenessEvaluationResult = statisticalAnalysisTools.managementEffectivenessEvaluation({
                        sheetData1: tempSheetData.current[0].sheetData,
                        sheetData2: tempSheetData.current[1].sheetData,
                    })
                    console.log("managementEffectivenessEvaluationResult--->", managementEffectivenessEvaluationResult)
                    let managementEffectivenessEvaluationParams = {
                        data: JSON.stringify({
                            paragraphList: managementEffectivenessEvaluationResult
                        })
                    }
                    systemApi.exportWordReport(managementEffectivenessEvaluationParams)
                        .then(res => {
                            downloadAndRenameFile(res.data.url, '自然保护地管理成效评价');
                            setSubmitLoading(false);
                        })
                        .catch(err => {
                            console.log("失败", err)
                            setSubmitLoading(false);
                            toastShort("error", commonErrorMsg);
                        })
                    break;
                default:
                    break;
            }
        } catch (errorInfo) {
            console.log("errorInfo---->", errorInfo)
            toastShort('error', commonErrorMsg);
        }
    };

    const handleCancel = () => {
        setIsModalOpen(false);
    };

    const convertSpeciesInfoToBJHspeciesInfo = (originSpeciesInfoList: SpeciesInfoType[]): BJHSpeciesInfoType[] => {
        let speciesInfoList = []
        originSpeciesInfoList.forEach(ele => {
            //@ts-ignore
            let item: BJHSpeciesInfoType = { ...ele };
            item.CIETS = ele.cites_protection_level;
            item.canorical_me = ele.canorical_me;
            //@ts-ignore
            item.endangered = ele.iucn_protection_level;
            item.state_protection_grade = ele.nationa_protection_level;
            //@ts-ignore
            item.class = ele.class_a;
            item.species_name = ele.species_c;
            speciesInfoList.push(item);

        })
        return speciesInfoList;
    }

    useEffect(() => {
        if (!isModalOpen) {
            setAnalysType(null);
            setCurrentFileName(null);
        }
    }, [isModalOpen])

    const onSelectYear = (e: string) => {
        setCurrentYear(e);
    }

    const uploadProps: UploadProps = {
        name: 'file',
        multiple: false,
        showUploadList: false,
        beforeUpload: (file) => {
            console.log("file---->", file);
            setCurrentFileName(file.name);
            let reader = new FileReader()
            reader.readAsBinaryString(file)//读取这个文件
            reader.onload = function (event) {
                try {
                    let result = event.target.result;
                    if (
                        analysType == 'EnvironmentalFactorAnalysis' ||
                        analysType == 'VegetationAndEcosystem' ||
                        analysType == 'ManagementEffectivenessEvaluation'
                    ) {
                        const sheetData: TypeWorkBookReadResult[] = readWorkBookData(result);
                        console.log("sheetData--->", sheetData)
                        tempSheetData.current = sheetData;
                    } else if (
                        analysType == 'LandUseTypeAnalysis' ||
                        analysType == 'SocialEconomicStatistics' ||
                        analysType == 'ManagementOrganizationAndPersonnel'
                    ) {
                        let xlsxdata = XLSX.read(result, { type: 'binary' })//读取xlsx
                        const workSheetNameList: string[] = xlsxdata.SheetNames;
                        if (workSheetNameList.length == 0) {
                            return toastShort('error', '上传文件中工作表为空，请检查上传文件！')
                        }
                        const workSheet: string[][] = XLSX.utils.sheet_to_json(xlsxdata.Sheets[workSheetNameList[0]], { header: 1, defval: '', blankrows: true });
                        tempWorkSheet.current = workSheet;
                    } else {
                        let xlsxdata = XLSX.read(result, { type: 'binary' })//读取xlsx
                        const workSheetNameList: string[] = xlsxdata.SheetNames;
                        if (workSheetNameList.length == 0) {
                            return toastShort('error', '上传文件中工作表为空，请检查上传文件！')
                        }
                        setCurrentFileName(file.name);
                        form.setFieldValue('currentFileName', file.name);
                        const workSheet: string[][] = XLSX.utils.sheet_to_json(xlsxdata.Sheets[workSheetNameList[0]], { header: 1, defval: '', blankrows: true });
                        const tempSpeciesNameList = [];
                        workSheet.forEach((row, rowIndex) => {
                            if (rowIndex > 0 && row[0]) {
                                tempSpeciesNameList.push(row[0])
                            }
                        })
                        let params = {
                            names: tempSpeciesNameList,
                            range: 'all'
                        }
                        systemApi.querySpeciesInfoMutiple(params)
                            .then(res => {
                                setLoading(false);
                                console.log("querySpeciesInfoMutiple--->", res)
                                let tempSpeciesInfoList = [];
                                tempSpeciesNameList.forEach(speciesName => {
                                    const find = res.data.list.find(ele => {
                                        return ele.species_c === speciesName;
                                    })
                                    if (find) {
                                        tempSpeciesInfoList.push(find)
                                    } else {
                                        tempSpeciesInfoList.push({
                                            species_c: speciesName
                                        })
                                    }
                                })
                                tempSpeciesInfoList.forEach(ele => {
                                    ele.speciesName = ele.species_c;
                                })
                                const mergedRowDataList = convertSpeciesInfoToBJHspeciesInfo(tempSpeciesInfoList);
                                setMergedRowDataList(mergedRowDataList);
                            })
                            .catch(err => {
                                setLoading(false);
                            })
                    }
                } catch (e) {

                }
            }
            return false;
        },
        onChange(info) {
        },
        onDrop(e) {
            console.log('Dropped files', e.dataTransfer.files);
        },
    };

    const adaptModalTitle = () => {
        let modalTitle = '';
        switch (analysType) {
            case 'SpeciesBook':
                modalTitle = '物种名录';
                break;
            case 'ProtectionSpeciesBook':
                modalTitle = '保护物种名录';
                break;
            case 'SpeciesStatistics':
                modalTitle = '科属种统计分析';
                break;
            case 'FloraAnalysisReport':
                modalTitle = '区系分析报告';
                break;
            case 'FloraStatistics':
                modalTitle = '区系统计';
                break;
            case 'ImporrantValueAnalysis':
                modalTitle = '重要值分析';
                break;
            case 'DiversityIndexAnalysis':
                modalTitle = '多样性指数分析';
                break;
            case 'EnvironmentalFactorAnalysis':
                modalTitle = '环境因子分析';
                break;
            case 'VegetationAndEcosystem':
                modalTitle = '植被与生态系统类型统计分析';
                break;
            case 'LandUseTypeAnalysis':
                modalTitle = '地类统计分析';
                break;
            case 'SocialEconomicStatistics':
                modalTitle = '社区经济统计';
                break;
            case 'ManagementOrganizationAndPersonnel':
                modalTitle = '自然保护地管理队伍';
                break;
            case 'ManagementEffectivenessEvaluation':
                modalTitle = '自然保护地管理成效评价';
                break;
            default:
                break;
        }
        return modalTitle;
    }

    const adaptTemplate = () => {
        switch (analysType) {
            case 'SpeciesBook':
            case 'ProtectionSpeciesBook':
            case 'SpeciesStatistics':
            case 'FloraAnalysisReport':
            case 'FloraStatistics':
            case 'ImporrantValueAnalysis':
            case 'DiversityIndexAnalysis':
                return (
                    <div
                        className="single-line-text link-text"
                        style={{ width: 320 }}
                        onClick={() => downloadAndRenameFile('http://shpfile-data-1314977817.cos.ap-guangzhou.myqcloud.com/public/20230525481f79f42b-b685-4bd9-a815-ff1eb69948f337.xlsx', '物种名单上传模板.xlsx')}
                        title={'物种名单上传模板.xlsx'}
                    >
                        <PaperClipOutlined />
                        物种名单上传模板.xlsx
                    </div>
                )
                break;
            case 'EnvironmentalFactorAnalysis':
                return (
                    <div
                        className="single-line-text link-text"
                        style={{ width: 320 }}
                        // onClick={() => downloadAndRenameFile('http://220.163.43.218:9001/ghzs_api/assets/uploads/规划助手环境因子数据导入模板.xlsx', '环境因子分析上传模板')}
                        onClick={() => downloadAndRenameFile('https://ghzsapi.zhbhd.cn/assets/uploads/2024-04-11/7635b17d-af2e-40b3-9795-1f3f8dbe257e规划助手环境因子数据导入模板.xlsx', '环境因子分析上传模板')}
                        title={'环境因子分析上传模板.xlsx'}
                    >
                        <PaperClipOutlined />
                        环境因子分析上传模板.xlsx
                    </div>
                )
                break;
            case 'VegetationAndEcosystem':
                return (
                    <div
                        className="single-line-text link-text"
                        style={{ width: 320 }}
                        // onClick={() => downloadAndRenameFile('http://220.163.43.218:9001/ghzs_api/assets/uploads/规划助手环境因子数据导入模板.xlsx', '植被与生态系统类型统计分析上传模板')}
                        onClick={() => downloadAndRenameFile('https://ghzsapi.zhbhd.cn/assets/uploads/2024-04-11/9987d56f-bfbf-43ba-a0f1-d5feaa8c89e5导入模板.xlsx', '植被与生态系统类型统计分析上传模板')}
                        title={'植被与生态系统类型统计分析上传模板.xlsx'}
                    >
                        <PaperClipOutlined />
                        植被与生态系统类型统计分析上传模板.xlsx
                    </div>
                )
                break;
            case 'LandUseTypeAnalysis':
                return (
                    <div
                        className="single-line-text link-text"
                        style={{ width: 320 }}
                        onClick={() => downloadAndRenameFile('http://220.163.43.218:9001/ghzs_api/assets/uploads/2024-04-19/6813c0c7-7959-4233-9e96-f9e431a3849c地类上传模板.xlsx', '地类统计分析')}
                        title={'地类统计分析.xlsx'}
                    >
                        <PaperClipOutlined />
                        地类统计分析.xlsx
                    </div>
                )
                break;
            case 'SocialEconomicStatistics':
                return (
                    <div
                        className="single-line-text link-text"
                        style={{ width: 320 }}
                        onClick={() => downloadAndRenameFile('http://shpfile-data-1314977817.cos.ap-guangzhou.myqcloud.com/public/20230824543cca7621-c09d-462e-b2a7-b70226fb7d4384.xlsx', '社区经济统计')}
                        title={'社区经济统计.xlsx'}
                    >
                        <PaperClipOutlined />
                        社区经济统计.xlsx
                    </div>
                )
                break;
            case 'ManagementOrganizationAndPersonnel':
                return (
                    <div
                        className="single-line-text link-text"
                        style={{ width: 320 }}
                        onClick={() => downloadAndRenameFile('http://shpfile-data-1314977817.cos.ap-guangzhou.myqcloud.com/public/2023082411acc6ad25-ff0a-4dfc-b8c5-ecbad195449998.xlsx', '自然保护地管理队伍')}
                        title={'自然保护地管理队伍.xlsx'}
                    >
                        <PaperClipOutlined />
                        自然保护地管理队伍.xlsx
                    </div>
                )
                break;
            case 'ManagementEffectivenessEvaluation':
                return (
                    <div
                        className="single-line-text link-text"
                        style={{ width: 320 }}
                        onClick={() => downloadAndRenameFile('http://shpfile-data-1314977817.cos.ap-guangzhou.myqcloud.com/public/2023082411acc6ad25-ff0a-4dfc-b8c5-ecbad195449998.xlsx', '自然保护地管理成效评价')}
                        title={'自然保护地管理成效评价.xlsx'}
                    >
                        <PaperClipOutlined />
                        自然保护地管理成效评价.xlsx
                    </div>
                )
                break;
            default:
                break;
        }
    }

    return (
        <Modal
            title={adaptModalTitle()}
            open={isModalOpen}
            onOk={handleConfirm}
            onCancel={handleCancel}
            okText={'确 认'}
            cancelText={'取 消'}
            width={'800px'}
            maskClosable={false}
            confirmLoading={submitLoading}
            centered
        >
            <div
                // style={{ height: 396 }}
                className='custom-modal-container'
            >
                <LoadingWapper
                    loading={loading}
                />
                <Form
                    size={'middle'}
                    form={form}
                    layout={'horizontal'}
                    autoComplete="off"
                    labelAlign={'right'}
                    labelCol={{ span: 6 }}
                >
                    <Form.Item
                        name="currentFileName"
                        label="导入文件"
                        required
                    >
                        <div>
                            <Dragger
                                {...uploadProps}
                                style={{ width: 525, paddingTop: 72, paddingBottom: 72 }}
                            >
                                <p className="ant-upload-drag-icon">
                                    <InboxOutlined />
                                </p>
                                <p className="ant-upload-text">
                                    {
                                        currentFileName ?
                                            currentFileName
                                            :
                                            '点击或拖拽附表文件到此处'
                                    }
                                </p>
                                <p className="ant-upload-hint">
                                    支持单次上传一个表格文件<br />(xlsx文件, 且大小在2M之内)
                                </p>
                            </Dragger>
                            <div
                                className="flex-row"
                                style={{ marginTop: 3 }}
                            >
                                {
                                    adaptTemplate()
                                }
                            </div>
                        </div>
                    </Form.Item>
                    {
                        analysType == 'EnvironmentalFactorAnalysis' ?
                            <Form.Item
                                name="currentYear"
                                label="统计年份"
                                rules={[{ required: true, message: "请选择统计年份" }]}
                            >
                                <Select
                                    options={yearOptions}
                                    placeholder={'请选择统计年份'}
                                    onChange={onSelectYear}
                                    style={{ width: 528 }}
                                />
                            </Form.Item>
                            :
                            null
                    }
                </Form>
            </div>
        </Modal>
    )
}


export default forwardRef(SpeciesNameFileModal);